package com.xq.tmall.agu.job.impl;


import com.xq.tmall.agu.ferign.StockHistorySpider;
import com.xq.tmall.agu.ferign.StockSectorHistorySpider;
import com.xq.tmall.agu.job.AbstractTimeJob;
import com.xq.tmall.container.SimpleTimerJobContainer;
import com.xq.tmall.util.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class StockSectorHistoryTimerJobImpl extends AbstractTimeJob {

    private SimpleTimerJobContainer stockSectorHistoryJob;

    public StockSectorHistoryTimerJobImpl() {
        name = "每日插入板块更新任务";
    }

    @Override
    public void execute(COMMAND command) {
        switch (command){
            case START:
                if (null == stockSectorHistoryJob) {
                    log.info("开启插入板块历史更新线程!");
                    StockSectorHistorySpider stockSectorHistorySpider = SpringContextUtil.getBean(StockSectorHistorySpider.class);
                    stockSectorHistoryJob = new SimpleTimerJobContainer(stockSectorHistorySpider,0,24, TimeUnit.HOURS,"stockSectorHistorySpider",4);
                    new Thread(stockSectorHistoryJob, "StockSectorHistoryJob").start();
                    status=STATUS.RUN;
                }
                break;
            case STOP:
                if (null != stockSectorHistoryJob) {
                    log.info("关闭插入板块历史更新线程!");
                    stockSectorHistoryJob.shutDown();
                    stockSectorHistoryJob = null;
                    status=STATUS.STOP;
                }
                break;
        }
    }
}
